<script type="text/javascript">
var [table];
$(function(){
	var pageSize = [rows];
	if (!pageSize) pageSize = 10;
	[table] = $.fn.bsgrid.init('[table]', {
		url: window.location.href,
    	pageSize: pageSize,
    	// autoLoad:false,
    	displayBlankRows:false,
    	event: {
            selectRowEvent: function (record, rowIndex, trObj, options) {
            	//
            	var id = [table].getRecordIndexValue(record, 'id');
            	$('#[table]-action').find('a[grid-btn]').each(function(idx,it){
            		$(this).removeClass('disabled');
            		var u = $(this).attr('href');
            		u = U('id',id,u);
            		$(this).attr('href',u);
            	})
            },
            unselectRowEvent: function (record, rowIndex, trObj, options) {
            	var id = [table].getRecordIndexValue(record, 'id');
            	$('#[table]-action').find('a[grid-btn]').each(function(idx,it){
            		$(this).addClass('disabled');
            		var u = $(this).attr('href');
            		u = U('id','',u);
            		$(this).attr('href',u);
            	})
            }
        },
	});


    $('[data-delete]').confirmation({
        container: 'body',
        href:false,
        onConfirm:function(event, element){
            event.preventDefault();
            el  = $(element);
            var url = el.attr('href');
            $.get(url,function(req){
                $.bootstrapGrowl(req.info);
                var st = req.status;
                [table].refreshPage();
            })
        }
    });


	$("#upload").fileinput({
		'showUpload':false,
		'previewFileType':'any',
		// 'uploadAsync': true,
		'maxFileCount': 5,
		'showUpload': true,
		// 'showPreview': false,

		'ajaxSettings':{
			headers: {
				'X-APICloud-AppId': 'A6986237580001',
				'X-APICloud-AppKey':'{$appKey}'
			},
		},
		'uploadUrl': 'http://d.apicloud.com/mcm/api/file',
	}).on('filebatchuploadcomplete',function (event, files, extra) {
		[table].refreshPage();
		$("#upload").fileinput('reset');
	});




})
function showImg(record, rowIndex, colIndex, options) {
	var url =  [table].getRecordIndexValue(record, 'url');
	if (url)
		return '<a target=_blank href='+url+'><img class="img img-responsive" src='+url+'></a>';
	else
		return '';
}
</script>
